
Component({
  data: {

  },
  properties: {
    date: {
      type: null,
      value: ''
    },
    format: {
      type: String,
      value: "yyyy年MM月dd日"
    }
  },
  attached() {
    let format = this.data.format;
    let date = this.data.date;
    date = dateFormat(format, date);
    console.log(date);
    this.setData({
      date: date
    })
  }
})
function dateFormat(fmt, date) {
  date = Math.round(date * 1000)
  date = new Date(+date);
  var o = {
    "y+": date.getFullYear(),
    "M+": date.getMonth() + 1, //月份
    "d+": date.getDate(), //日
    "h+": date.getHours(), //小时
    "m+": date.getMinutes(), //分
    "s+": date.getSeconds(), //秒
    "q+": Math.floor((date.getMonth() + 3) / 3), //季度
    "S+": date.getMilliseconds() //毫秒
  };
  for (var k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) {
      if (k == "y+") {
        fmt = fmt.replace(RegExp.$1, ("" + o[k]).substr(4 - RegExp.$1.length));
      } else if (k == "S+") {
        var lens = RegExp.$1.length;
        lens = lens == 1 ? 3 : lens;
        fmt = fmt.replace(RegExp.$1, ("00" + o[k]).substr(("" + o[k]).length - 1, lens));
      } else {
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
      }
    }
  }
  return fmt;
}